Skip to content

feat(cli): run a Remix app's own server in the console Preview, like the platform - #1029

Merged
edgar-durand merged 1 commit into
mainfrom
feat/remix-app-server-preview
Nov 23, 2026
Merged

edgar-durand merged 1 commit into
mainfrom
feat/remix-app-server-preview

Conversation

@edgar-durand

@edgar-durand edgar-durand commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Why

Owner, 2026-11-23: a Remix project's server/ has to work in the console Preview the same way it does on the Remix feed/player. Until now the Preview only started the client.

What

  • remix-app-server.ts: when remix.json declares "server", the preview runs wrangler dev (workerd + local D1). The generated config uses the platform's bindings from remix-cloudflare.ts:
    • compatibility date 2026-08-01 + nodejs_compat
    • D1 as DB, with server/migrations applied first (wrangler d1 migrations apply DB --local)
    • ROOMS → Room (migration tag rooms-v1)
    • the "env" names, with values read from the project .env. Secrets go in a 0600 .dev.vars, never in argv.
    • State lives in .wrangler/state and survives restarts.
    • wrangler is the project's own copy, or a pinned install in ~/.codeam/tools (4.158.0 on Node ≥22, 4.85.0 on Node 20).
  • app-server-proxy.ts: sits between cloudflared and the dev server and routes like dispatch.ts. /_v/local/<server path> goes to wrangler with the prefix stripped and the X-Remix-* headers set (a client's forged ones are dropped). For phone apps it prepends globalThis.__REMIX_SERVER_BASE__="<public origin>/_v/local/" to Metro JS bundles, for web and Expo Go alike. Web apps get their root server paths routed. No CORS, no second tunnel, no edits to the app's code.
  • Orchestrator / killPreview: the preview is ready once both the server and the dev server are up. Stop and restart kill both, and a failed bring-up kills the server.
  • Expo: now started with EXPO_NO_TYPESCRIPT_SETUP=1. A Remix MOBILE export has .tsx files and no typescript dependency, and a non-interactive expo start was exiting with an error.

Verified live (local Mac)

Fixture: a Remix MOBILE export with server/ (Hono + D1 migration + src/api/client.ts reading __REMIX_SERVER_BASE__). It went through the real detectKnownProject + runPreviewStart, with a real quick tunnel:

  • The bundle served through the tunnel starts with globalThis.__REMIX_SERVER_BASE__="https://<tunnel>/_v/local/", for both platform=web and platform=ios.
  • In headless Chrome on the public URL, the app showed the base and listed rows. Tapping Add sent POST /_v/local/api/items 201 and the new row appeared.
  • A row written in one run was still there after stopping and restarting the preview (D1 persisted).
  • Stopping freed wrangler, Metro and cloudflared.

Tests

New __tests__/preview/remix-app-server.test.ts (config generation, .dev.vars permissions, routing, prelude, identity headers, and a live proxy against fake servers). tsc is clean. Full CLI suite: 3628 passed. The one failure (acp.adapterModuleGraph.int) also fails on main on this machine.

🤖 Generated with Claude Code


Show it working
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…the platform

A Remix project whose remix.json declares "server" now gets its server/ beside
the front: `wrangler dev` (workerd + a local D1) with a generated config that
carries the platform's bindings (D1 as DB with server/migrations applied first,
ROOMS -> Room with tag rooms-v1, the remix.json "env" names with values from the
project .env, secrets in a 0600 .dev.vars), state in .wrangler/state.

The app-server proxy puts it on the preview's own origin the way the platform
Worker does: /_v/local/{api,auth,webhooks,ws,__cron,__check-env} -> the server
with the prefix stripped and the X-Remix-* identity headers, and for a phone app
`globalThis.__REMIX_SERVER_BASE__ = "<public origin>/_v/local/"` is prepended to
every Metro JS bundle (web and Expo Go), so the app's code is not edited. Web
apps get their root server paths routed. killPreview stops both.

Expo now starts with EXPO_NO_TYPESCRIPT_SETUP=1: a Remix MOBILE export has .tsx
files and no typescript dependency, and a non-interactive `expo start` exited.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@edgar-durand
edgar-durand merged commit de81938 into main Nov 23, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants